﻿using CrystalDecisions.CrystalReports.Engine;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace THEMXOASUA
{
    
    public partial class DSHOADON : Window
    {
        public DSHOADON()
        {
            InitializeComponent();
        }
        private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {
            DataTable DT = hoadon.DanhSachHoaDon();
            datagrid.ItemsSource = DT.DefaultView;
            datagrid.SelectedValuePath = "sohd";
        }
        HOADON hoadon = new HOADON();
        HOADONWIN HDON = new HOADONWIN();

        private void mnxoa_Click_1(object sender, RoutedEventArgs e)
        {
            string shd = datagrid.SelectedValue.ToString();
            MessageBoxResult result = MessageBox.Show(" bạn có muốn xóa hóa đơn" + shd +" không?", "THÔNG BÁO", MessageBoxButton.YesNo, MessageBoxImage.Warning);
            if (result == MessageBoxResult.Yes)
            {    
                hoadon.XOAHOADON(shd);
                DataRowView rowSelect = (DataRowView)datagrid.SelectedItem;
                rowSelect.Delete();
            }
        }

        private void BTCLOSE_Click_1(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void update_Click_1(object sender, RoutedEventArgs e)
        {
            DataRowView row = (DataRowView)datagrid.SelectedItem;
            HOADONWIN hdw = new HOADONWIN(row,false);
            hdw.ShowDialog();
            row.EndEdit();
            datagrid.Items.Refresh();
        }

        private void SEARCH_Click_1(object sender, RoutedEventArgs e)
        {

        }

        private void mnNew_Click_1(object sender, RoutedEventArgs e)
        {
            DataView dv = (DataView)datagrid.ItemsSource;
            DataRowView row = dv.AddNew();
            HOADONWIN hdw =new HOADONWIN(row,true);
            hdw.ShowDialog();
            row.EndEdit();
            datagrid.Items.Refresh();
        
        }
        REPORTVIEWER re = new REPORTVIEWER();
        private void in_Click_1(object sender, RoutedEventArgs e)
        {
            DataTable tb = hoadon.DanhSachHoaDon();
            tb.TableName = "DSHOADON";
            DataSet ds = new DataSet();
            ds.DataSetName = "DSHOADON";
            ds.Tables.Add(tb);
            ReportDocument report = new ReportDocument();
            report.Load("..\\..\\CrystalReport3.rpt");
            report.SetDataSource(ds);
            REPORTVIEWER rv = new REPORTVIEWER(report);
            rv.Show();
        }
    }
}